#ifndef CMDTHREAD_H
#define CMDTHREAD_H

#include <QObject>
#include <QThread>
#include <QDateTime>
#include <QMutex>
#include <QProcess>

class CmdThread : public QThread
{
    Q_OBJECT
public:
    enum CMDSTAT{
        CMD_PREPARE = 0,
        CMD_RUNING  = 1,
        CMD_END     = 2,
        CMD_TIMEOUT = 3,
        CMD_CRASHEND = 4,
    };
    explicit CmdThread(QString cmdstr, int outTimes, QString hostIP);
    QString GetCmdstr();
    QString GetCmdOutstr();
    QString GetHostIP();
    int GetRumTimes();
    QString GetErrstr();
    void killRun();
    void run(void);

signals:
    void cmdStatChanged(QString cmdstr, int stat);

private:
    bool        isKilled;
    QProcess    cmdgExec;
    QMutex      cmdMutex;
    QString     cmdstr;
    QDateTime   cmdStartTime;
    QString     cmdOutstr;          //命令运行过程中，输出的反馈值
    QString     cmdErrstr;          //命令异常运行结束后，提供的报错信息
    QString     hostIP;
    int outTimes;
    int runTimes;
};

#endif // CMDTHREAD_H
